package com.service.impl;

import com.dao.FlightDao;
import com.dao.impl.FlightDaoImpl;
import com.pojo.Flight;
import com.service.FlightService;

import java.util.List;

/**
 * 业务实现层 调用dao层执行sql语句完成增删改查操作
 */
public class FlightServiceImpl implements FlightService {
    FlightDao flightDao = new FlightDaoImpl();
    @Override
    public List<Flight> selectAllFlight(String page, String limit) {
        //根据传入的页码和每页显示的数量，查询所有航班
        return flightDao.selectAllFlight(page,limit);
    }

    @Override
    public int countFlight() {
        //查询航班的数量
        return flightDao.countFlight();
    }

    @Override
    public void insertFlight(Flight flight) {
        //插入航班信息
        flightDao.insertFlight(flight);
    }

    @Override
    public Flight selectFlightById(Integer flightId) {
        //根据航班ID查询航班信息
        return flightDao.selectFlightById(flightId);
    }

    @Override
    public void updateFlightById(Integer flightId, Flight flight) {
        //根据航班ID更新航班信息
        flightDao.updateFlightById(flightId,flight);
    }

    @Override
    public void deleteFlightById(Integer flightId) {
        //根据航班ID删除航班信息
        flightDao.deleteFlightById(flightId);
    }

    @Override
    public List<String> selectstartAdd() {
        //查询所有起始地机场
        return flightDao.selectstartAdd();
    }

    @Override
    public int countAdd(String address) {
        //查询指定机场的航班数量
        return flightDao.countAdd(address);
    }

    @Override
    public List<Flight> selectFlightByAddAndDate(String startAdd, String targetAdd, String date,String page, String limit) {
        //根据起始地机场、目的地机场和日期查询航班信息，并按照页码和每页显示的数量进行排序
        return flightDao.selectFlightByAddAndDate(startAdd,targetAdd,date,page,limit);
    }

    @Override
    public int selectFlightByAddAndDateCount(String startAdd, String targetAdd, String date) {
        //根据起始地机场、目的地机场和日期查询航班数量
        return flightDao.selectFlightByAddAndDateCount(startAdd, targetAdd, date);
    }

    @Override
    public void updateSeats(Integer flightId, String option) {
        //根据航班ID更新座位数量，option为'add'时增加座位，为'sub'时减少座位
        flightDao.updateSeats(flightId, option);
    }
}
